<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>变量在函数内声明，变量为局部作用域</title>
</head>

<body>
    <p>局部变量在声明的函数外不可以访问。</p>
    <p id="demo"></p>
    <script>
        myFunction();
        document.getElementById("demo").innerHTML = "carName 的类型是：" + typeof carName;
        function myFunction() {
            var carName = "Volvo";
        }
    </script>
</body>

</html>